<?php
/**
 * Created by PhpStorm.
 * User: mojie126
 * Date: 2017/7/28 0028
 * Time: 上午 9:45
 */
define('ADMIN_USERNAME', 'mojie126');
define('ADMIN_PASSWORD', 'a123456');
header("Content-type: text/html; charset=utf-8");

if (!isset($_SERVER['PHP_AUTH_USER']) || !isset($_SERVER['PHP_AUTH_PW']) ||
	$_SERVER['PHP_AUTH_USER'] != ADMIN_USERNAME || $_SERVER['PHP_AUTH_PW'] != ADMIN_PASSWORD
) {
	header("WWW-Authenticate: Basic realm=\"ConfigEdit Login\"");
	header("HTTP/1.0 401 Unauthorized");

	echo <<<EOB
				<html><body>
				<h1>Rejected!</h1>
				<big>Wrong Username or Password!</big>
				</body></html>
EOB;
	exit;
}
$file = isset($_REQUEST['filename']) ? $_REQUEST['filename'] : "";
$myfile = file_get_contents("../config/" . $file);
if (isset($_REQUEST['submit'])) {
	$a1 = fopen($file, "w");
	fwrite($a1, $_REQUEST['content']);
	fclose($a1);
	echo "<script>location.href='edit.php';</script>";
}
?>
<!DOCTYPE html>
<html>
<head>
	<title>ConfigEdit</title>
	<!-- ZUI 标准版压缩后的 CSS 文件 -->
	<link rel="stylesheet" href="zui/css/zui.min.css">
	<!-- ZUI Javascript 依赖 jQuery -->
	<script src="zui/lib/jquery/jquery.js"></script>
	<!-- ZUI 标准版压缩后的 JavaScript 文件 -->
	<script src="zui/js/zui.min.js"></script>
</head>
<body>
<div class="container-fixed">
	<hr>
	<form method="get" style="height: 850px" action="edit.php">
		<textarea class="form-control" style="height: 95%" name="content"><?php echo $myfile; ?></textarea>
		<br>
		<input class="btn btn-primary pull-right" type="submit" name="submit"/>
	</form>
	<hr>
</div>
</body>
</html>
